package ThreadPoolCheck.notify_wait.Cond1;

/**
 * Created by wangyg6 on 2017/11/9.
 */
public class UseSynchronized {

	private boolean bShouldSub = true;

	public synchronized void sub(int i) {
		while (!bShouldSub) {
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		for (int j = 1; j <= 10; j++) {
			System.out.println("sub thread sequence of " + j + ",loop of " + i);
		}
		System.out.println();
		System.out.println();
		bShouldSub = false;
		this.notify();
	}

	public synchronized void main(int i) {
		while (bShouldSub) {
			try {
				this.wait();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		for (int j = 1; j <= 10; j++) {
			System.out.println("main thread sequence of " + j + ",loop of " + i);
		}
		System.out.println();
		System.out.println();
		bShouldSub = true;
		this.notify();
	}
}
